<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2024/11/21
  Time: 12:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-L-admin1.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="${pageContext.request.contextPath}/static/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/xadmin.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/dialog.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/js/dialog.js">
    <script src="${pageContext.request.contextPath}/static/js/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/lib/layui/layui.js"
            charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->


</head>

<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">演示</a>
        <a>
          <cite>导航元素</cite></a>
      </span>
</div>
<div class="x-body">
    <div class="layui-row">

        <form class="layui-form layui-col-md12 x-so" id="f1"
              action="${pageContext.request.contextPath}/logistics/findAll.do">
            <button class="layui-btn" type="submit" lay-submit="" lay-filter="sreach"><i class="layui-icon">刷新</i>
                <button class="layui-btn" id="re" type="button"><i class="layui-icon">清空</i>
            </button>
            <input type="text" id="like" name="likename" placeholder="请输入订单号" autocomplete="off" class="layui-input"
                   value="${likename}">
            <button class="layui-btn" type="submit" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i>
            </button>
            <input type="hidden" id="pageNumA" name="pageNumA" value="${Page.pageNum}">
                <input type="hidden" id="pageNumB" name="pageNumB" value="${PageB.pageNum}">
            <input type="hidden" id="pageSize" name="pageSize">

        </form>
    </div>
       <center> <h3>销售订单</h3></center>
    <hr>
    <xblock>
        <button class="layui-btn layui-btn-danger" ><i class="layui-icon"></i></button>
        <button class="layui-btn" ></button>
        <button class="layui-btn layui-bg-blue" type="button">
        </button>
        <span class="x-right" style="line-height:40px">
            当前第${PageB.pageNum}页 总共${PageB.pages}页，共${PageB.total}条数据
        </span>
    </xblock>
    <table class="layui-table">
        <thead>
        <tr>
            <th>订单号</th>
            <th>时间</th>
            <th>金额</th>
            <th>地址</th>
            <th>电话</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach var="material" items="${PageB.list}">
            <tr>
                <td>${material.orderId}</td>
                <td>
                    <fmt:formatDate value="${material.orderTime}" pattern="yyyy-MM-dd HH:mm:ss"></fmt:formatDate>
                </td>
                <td>${material.orderMoney}</td>
                <td>${material.orderAddress}</td>
                <td>${material.orderUphone}</td>

                <td>
                    <c:if test="${material.orderState==1}">待发货</c:if>
                    <c:if test="${material.orderState==2}">已发货</c:if>
                    <c:if test="${material.orderState==3}">运输中</c:if>
                </td>
                <td class="td-manage">
                    <c:if test="${material.orderState==1}"><button onclick="tanchuang('生成物流订单','3','${material.orderId}')">生成物流订单</button></c:if>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>

    <div class="page">
        <div>
            <a href="javascript:goB(1)" class="num">首页</a>
            <c:if test="${PageB.hasPreviousPage}">
                <a class="prev" href="javascript:goB('${PageB.prePage}')">&lt;&lt;</a>
            </c:if>
            <c:choose>
                <c:when test="${PageB.pages<=10}">
                    <c:set var="begin" value="1"></c:set>
                    <c:set var="end" value="${PageB.pages}"></c:set>
                </c:when>
                <c:otherwise>
                    <c:set var="begin" value="${PageB.pageNum-5}"></c:set>
                    <c:set var="end" value="${PageB.pageNum+4}"></c:set>
                    <c:if test="${begin<1}">
                        <c:set var="begin" value="1"></c:set>
                        <c:set var="end" value="10"></c:set>
                    </c:if>
                    <c:if test="${end>PageB.pages}">
                        <c:set var="begin" value="${PageB.pages-9}"></c:set>
                        <c:set var="end" value="${PageB.pages}"></c:set>
                    </c:if>
                </c:otherwise>
            </c:choose>
            <c:forEach var="i" begin="${begin}" end="${end}">
                <c:choose>
                    <c:when test="${PageB.pageNum eq i}">
                        <span class="current">${i}</span>
                    </c:when>
                    <c:otherwise>
                        <a class="num" href="javascript:goB(${i})">${i}</a>
                    </c:otherwise>
                </c:choose>
            </c:forEach>
            <%--            --%>
            <%--            <a class="num" href="">3</a>--%>
            <%--            <a class="num" href="">489</a>--%>
            <c:if test="${PageB.hasNextPage}">
                <a class="next" href="javascript:goB('${PageB.nextPage}')">&gt;&gt;</a>
            </c:if>
            <a href="javascript:goB(${PageB.pages})" class="num">尾页</a>
        </div>
    </div>
    <hr>
    <center> <h3>物流订单</h3></center>
    <hr>
    <xblock>
<%--        <i class="layui-icon"></i>--%>
<%--    <i class="layui-icon"></i>--%>
        <button class="layui-btn layui-btn-danger" onclick="lodiAll()"><i class="layui-icon"></i>批量存入</button>
        <button class="layui-btn" onclick="tanchuang('修改订单', 1, 1)">订单异常</button>
        <button class="layui-btn layui-bg-blue" type="button"onclick="tanchuang('历史订单', 2, -1)">
          历史订单
        </button>


        <span class="x-right" style="line-height:40px">
            当前第${Page.pageNum}页 总共${Page.pages}页，共${Page.total}条数据
        </span>
    </xblock>
    <table class="layui-table">
        <thead>
        <tr>
            <th>
                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary">
                    <i class="layui-icon">&#xe605;</i>
                </div>
            </th>
            <th>物流编号</th>
            <th>发货信息</th>
            <th>收货信息</th>
            <th>发货时间</th>
            <th>到货时间</th>
            <th>物品描述</th>
            <th>备注</th>
            <th>配送员</th>
            <th>电话</th>
            <th>物流状态</th>
            <th>操作</th>
        </thead>
        <tbody>
        <c:forEach var="material" items="${Page.list}">
            <tr>
                <td>
                    <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='${material.logisticsId}'>
                        <i class="layui-icon">&#xe605;</i></div>
                </td>
                <td>${material.logisticsId}</td>
                <td>${material.startPoint}</td>
                <td>${material.endPoint}</td>
                <td>
                    <fmt:formatDate value="${material.departureTime}" pattern="yyyy-MM-dd HH:mm:ss"></fmt:formatDate>
                </td>
                <td>
                    <fmt:formatDate value="${material.arrivalTime}" pattern="yyyy-MM-dd HH:mm:ss"></fmt:formatDate>
                </td>

                <td>${material.itemDescription}</td>
                <td>${material.remarks}</td>
                <td>${material.name}</td>
                <td>${material.phone}</td>
                <td>
                    <c:if test="${material.status==-1}">未揽货</c:if>
                    <c:if test="${material.status==0}">已揽货</c:if>
                    <c:if test="${material.status==1}">运输中</c:if>
                    <c:if test="${material.status==2}">已签收</c:if>
                        </td>
                <td class="td-manage">
                    <c:if test="${material.status==-1}"> <button onclick="updateStatu(${material.logisticsId},'0')">已揽货</button></c:if>
                    <c:if test="${material.status==0}"><button onclick="updateStatu(${material.logisticsId},'1')">已发货</button></c:if>
                    <c:if test="${material.status==1}"><button onclick="updateStatu(${material.logisticsId},'2')">已签收</button></c:if>
                    <c:if test="${material.status==2}"><button onclick="updateStatu(${material.logisticsId},'3')">存入</button></c:if>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>

    <div class="page">
        <div>
            <a href="javascript:go(1)" class="num">首页</a>
            <c:if test="${Page.hasPreviousPage}">
                <a class="prev" href="javascript:go('${Page.prePage}')">&lt;&lt;</a>
            </c:if>
            <c:choose>
                <c:when test="${Page.pages<=10}">
                    <c:set var="begin" value="1"></c:set>
                    <c:set var="end" value="${Page.pages}"></c:set>
                </c:when>
                <c:otherwise>
                    <c:set var="begin" value="${Page.pageNum-5}"></c:set>
                    <c:set var="end" value="${Page.pageNum+4}"></c:set>
                    <c:if test="${begin<1}">
                        <c:set var="begin" value="1"></c:set>
                        <c:set var="end" value="10"></c:set>
                    </c:if>
                    <c:if test="${end>Page.pages}">
                        <c:set var="begin" value="${Page.pages-9}"></c:set>
                        <c:set var="end" value="${Page.pages}"></c:set>
                    </c:if>
                </c:otherwise>
            </c:choose>
            <c:forEach var="i" begin="${begin}" end="${end}">
                <c:choose>
                    <c:when test="${Page.pageNum eq i}">
                        <span class="current">${i}</span>
                    </c:when>
                    <c:otherwise>
                        <a class="num" href="javascript:go(${i})">${i}</a>
                    </c:otherwise>
                </c:choose>
            </c:forEach>
            <%--            --%>
            <%--            <a class="num" href="">3</a>--%>
            <%--            <a class="num" href="">489</a>--%>
            <c:if test="${Page.hasNextPage}">
                <a class="next" href="javascript:go('${Page.nextPage}')">&gt;&gt;</a>
            </c:if>
            <a href="javascript:go(${Page.pages})" class="num">尾页</a>
        </div>
    </div>

</div>

<!-- 弹窗内容 -->
<%--<div id="myModal" class="modal">--%>
<%--    <div class="modal-content">--%>
<%--        <span class="close">&times;</span>--%>
<%--        <form method="post" action="${pageContext.request.contextPath}/user/fileIn.do" enctype="multipart/form-data"--%>
<%--              onsubmit="return fileIn()">--%>
<%--            <input type="file" id="file" name="file" accept=".xls,.xlsx">--%>
<%--            <span id="fileMsg" style="color: red"></span>--%>
<%--            <div>--%>
<%--                <input type="button" value="取消">--%>
<%--                <input type="submit" value="确定">--%>
<%--            </div>--%>
<%--        </form>--%>
<%--    </div>--%>
<%--</div>--%>

<script>

    $("#sel").change(function () {
        $("#pageSize").val($("#sel").val())
        $("#pageNum").val(1)
        $("#f1").submit()
    })

    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });
    });

    function go(pageNum) {
        $("#pageSize").val($("#sel").val())
        $("#pageNumA").val(pageNum)
        $("#f1").submit()
    }
    function goB(pageNum) {
        $("#pageSize").val($("#sel").val())
        $("#pageNumB").val(pageNum)
        $("#f1").submit()
    }
    function addMaterial() {
        window.location.href = "${pageContext.request.contextPath}/product/findMaterialCategoryAll.do"
    }

    function addMaterialCategory() {
        window.location.href = "${pageContext.request.contextPath}/jsp/addMaterialCategory.jsp"
    }

    function lodiAll(argument) {
        var data = tableCheck.getData();
        var pageNum="";
        if ( $("#pageNumA").val()!=null){
            pageNum=$("#pageNumA").val();
        }
        if (data.length > 0) {
            layer.confirm('确认要存入已签收的订单'+data+'吗？', function (index) {
                var ids = []
                for (var i = 0; i < data.length; i++) {
                    ids.push(data[i])
                }
                window.location.href = "${pageContext.request.contextPath}/logistics/updateStatuArr.do?ids=" + ids+"&&pageNum=" + pageNum;
                layer.msg('删除成功', {icon: 1});
            });
        } else {
            layer.confirm('至少选择一个要存入的已签收订单')
        }

    }

    $("#re").click(function () {
        $("#like").val("")
        $(".layui-input").val("")
    })

    function updateStatu(logisticsId, number) {
        var pageNum="";
        if ( $("#pageNumA").val()!=null){
            pageNum=$("#pageNumA").val();
        }
        window.location.href = "${pageContext.request.contextPath}/logistics/updateStatu.do?logisticsId=" + logisticsId + "&&pageNum=" + pageNum+"&&number="+number;
    }

    function tanchuang(title,url,id){
        var data = tableCheck.getData();
        if (url == 1) {
            if (data.length ==1) {
                id=data[0]
                url="${pageContext.request.contextPath}/logistics/tanchuang.do?id="+id;
            }else {
                layer.confirm('请选择单个异常订单')
                return;
            }
        };
        if (url==2){
            url="${pageContext.request.contextPath}/logistics/findAll3.do";
        }
        if (url == null || url == '') {
            url="404.html"
        };
        if (url==3){
            url="${pageContext.request.contextPath}/logistics/generate.do?id="+id;
        }
        if (url==4){
            url="${pageContext.request.contextPath}/logistics/tanchuang.do?id="+id;
        }
        layer.open({
                    type: 2,
                    area: [($(window).width()*0.9)+'px', ($(window).height() - 50) +'px'],
                    fix: false, //不固定
                    maxmin: true,
                    shadeClose: true,
                    shade:0.4,
                    title: title,
                    content: url
                });



    }
</script>
</body>

</html>
